from common.Base import open_browser, Base
from selenium.webdriver.common.by import By

login_url = "http://localhost:8080/ecshop/user.php?act=register"


class Register_page(Base):
    user_loc = ("name", "username")
    email_loc = ("name", "email")
    password_loc = ("name", "password")
    confirm_password_loc = ("name", "confirm_password")
    extend_field5_loc = ("name", "extend_field5")
    login_loc = ("name", "Submit")
    qq_loc = ("name", "extend_field2")
    office_tel_loc = ("name", "extend_field3")
    home_tel_loc = ("name", "extend_field4")
    question_loc = ("name", "sel_question")
    answer_loc = ("name", "passwd_answer")
    agreement_loc = ("name", "agreement")

    # 定位用户名并输入
    def input_username(self, username):
        self.send_text(self.user_loc, username)

    # 定位邮箱并输入
    def input_email(self, email):
        self.send_text(self.email_loc, email)

    # 定位密码并输入
    def input_password(self, password):
        self.send_text(self.password_loc, password)

    # 定位确认密码并输入
    def input_confirm_password(self, confirm_password):
        self.send_text(self.confirm_password_loc, confirm_password)

    # 定位手qq号并输入
    def input_qq_number(self, qq_num):
        self.send_text(self.qq_loc, qq_num)

    # 定位办公电话并输入
    def input_office_tel(self, office_tel):
        self.send_text(self.office_tel_loc, office_tel)

    # 定位家庭电话并输入
    def input_home_tel(self, home_tel):
        self.send_text(self.home_tel_loc, home_tel)

    # 定位手机号并输入
    def input_extend_field5(self, phone):
        self.send_text(self.extend_field5_loc, phone)

    # 定位密码提示问题
    def question(self, quest):
        self.select_by_text(self.question_loc, quest)

    # 定位密码问题答案
    def answer(self, answer):
        self.send_text(self.answer_loc, answer)

    # 定位取消勾选 阅读协议
    def user_agreement(self):
        self.click(self.agreement_loc)

    # 点击注册
    def click_login(self):
        self.click(self.login_loc)


if __name__ == '__main__':
    # 打开浏览器
    driver = open_browser()
    # 打开网页
    lg = Register_page(driver)
    lg.open_url(login_url)
    # 输入用户名
    lg.input_username("jiao1")
    # 输入email
    lg.input_email("jiao123@qq.com")
    # 输入密码
    lg.input_password("123456")
    # 输入确认密码
    lg.input_confirm_password("123456")
    # 输入手机号
    lg.input_extend_field5("11111111111")
    lg.question(1)
    lg.answer("1111")
    # 点击注册
    lg.click_login()
